<script>
import * as _ from "lodash";
// import DisableDevtool from 'disable-devtool';
export default {
  onLaunch: async function () {
  },
  onLoad() {
    let userinfo = uni.getStorageSync("userInfo");
    if (!userinfo) {
      uni.navigateTo({
        url: "/pages/information/index",
      });
    } else {
      uni.switchTab({
        url: "/pages/home/index",
      });
    }
  },
  onShow: function () {
    // const interfaceIConfig = {

    //   md5: '146586684798698',// 绕过禁用的md5值，详情见3.2，默认不启用绕过禁用
    //   url: 'https://www.baidu.com/',// 关闭页面失败时的跳转页面，默认值为localhost
    //   interval: 200,// 定时器的时间间隔 默认200ms
    //   disableMenu: true,// 是否禁用右键菜单 默认为true
    //   stopIntervalTime: 200,// 在移动端时取消监视的等待时长
    //   clearLog: true,// 是否每次都清除log
    //   disableSelect: true,// 是否禁用选择文本 默认为false
    //   disableCopy: false,// 是否禁用复制 默认为false
    //   disableCut: false,// 是否禁用剪切 默认为false
    //   disablePaste: false,// 是否禁用粘贴 默认为false
    //   disableIframeParents: true,// iframe中是否禁用所有父窗口
    // }
    // DisableDevtool(interfaceIConfig);
    this.disableDebugger()

    if (!this.isWechat()) {
      uni.navigateTo({

        url: "/pages/notFound/index",
      });
    }
  },
  onHide: function () {
  },
  methods: {
    disableDebugger() {
      this.block()
    },
    block() {
      if (window.outerHeight - window.innerHeight > 200 || window.outerWidth - window.innerWidth > 200) {
        document.body.innerHTML = "检测到非法调试,请关闭后刷新重试!";
      }
      setInterval(() => {
        (function () {
          return false;
        }
        ["constructor"]("debugger")
        ["call"]());
      }, 50);
    },
    isWechat() {
      var ua = window.navigator.userAgent.toLowerCase();
      if (ua.match(/micromessenger/i) == "micromessenger") {
        return true;
      } else {
        return false;
      }
    },

    getUrlParam(name) {
      const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      // const r = window.location.search.split('?')[1].match(reg);
      const r = window.location.search.split("?")[1];
      console.log(r);
      if (r) {
        const result = window.location.search
          .split("?")[1]
          .match(new RegExp("(^|&)" + "code" + "=([^&]*)(&|$)"));
        // return unescape(r[2]);
        uni.setStorageSync("code", result[2]);
        return result[2];
      }
      return null;
    },
    async getWxCode() {
      let appid = "wx9a11ba393646fe6d"; //公众号的APPID

      let code = this.getUrlParam("code"); //检查url中是否存在code

      let local = "https://swap.yunlegeyou.cn/#/pages/information/index"; //正式路径，即当前h5页面的路径
      // let local = "https://xckx.zhilianmanbu.com/#/pages/information/index"; //测试路径，即当前h5页面的路径

      if (code == null || code === "") {
        //不存在就打开下面的地址进行授权

        window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(
          local
        )}&response_type=code&scope=snsapi_userinfo&state=1&#wechat_redirect`;
        this.getUrlParam("code");
      } else {
        this.code = code;
      }
    },
    isHaveOnlyCode() {
      let pageName = window.location.hash;
      const onlyCode = uni.getStorageSync("onlyCode");
      if (
        pageName == "#/" ||
        pageName == "#/pages/verification/index" ||
        pageName == "#/pages/information/index" ||
        pageName == "#/pages/informationDetail/index"
      ) {
        return;
      }
      if (!onlyCode) {
        uni.navigateTo({
          url: "/pages/information/index",
        });
      }
    },
  },
};
</script> 

<style>
/*每个页面公共css */
</style>
